<?php 
	include_once('Configs/paging.php');
	//include_once('Models/HocKiNamHoc.php');
	include_once('Models/Quyen.php');
    include_once('Models/ChucNang.php');
    include_once('Models/BoMon.php');
?>
<script type="text/javascript" src="Libraries/js/js.js"></script>
<script type="text/javascript" src="Libraries/js/jquery.min.js"></script>
<script type="text/javascript" src="Libraries/js/jquery.datepick.js"></script>
<script language="javascript">





//******************* CÁC HÀM ĐƯỢC THÊM VÀO (NGUYỄN NGỌC CHÁNH-1081546)************************************

// Hàm kiểm tra email có hợp lệ không?
function check_mail(kt) {
		var rs = new RegExp("([A-Za-z0-9_.-]){2,}@([A-Za-z0-9_.-]){2,}.([A-Za-z0-9_.-]){2,}");
		if(kt.match(rs) == null) 
		return false;
		else 
		return true;
    }
// Hàm kiểm tra năm nập vào có lớn hơn năm hiện tại không?
function check_year() {
		var ngaysinh = document.capnhatcanbo.txtngaysinh.value;
		var year= ngaysinh.split('-');
		var y=parseInt(year[2]);
		var t= new Date();
		var ht=t.getFullYear();
		if( y >= ht )
		return false;
		else 
		return true;
		
}

//***********************************************************************************************






function checkField(){
	var year =new Date();
	var loaicb = document.capnhatcanbo.cboloaicb.value;
	var maso = document.capnhatcanbo.txtmaso.value;
	var holot = document.capnhatcanbo.txtholot.value;
	var ten = document.capnhatcanbo.txtten.value;
	var ngaysinh = document.capnhatcanbo.txtngaysinh.value;
	var indexphai = document.capnhatcanbo.cbophai.selectedIndex;
	var sodt = document.capnhatcanbo.txtsodt.value;
	var diachi = document.capnhatcanbo.txtdiachi.value;
	var email = document.capnhatcanbo.txtemail.value;
	var indexhocvi = document.capnhatcanbo.cbohocvi.selectedIndex;
	var nghiepvu = document.capnhatcanbo.txtnghiepvu.value;
	var indexchucdanh = document.capnhatcanbo.cbochucdanh.selectedIndex;
	
	var indexbomon = document.capnhatcanbo.cbobomon.selectedIndex;
	if (loaicb="" || maso == "" || holot == "" || ten == "" || ngaysinh == "" || sodt == "" || diachi == "" || email == "" || indexhocvi == 0 ){
		alert("Xin vui lòng nhập đầy đủ thông tin được yêu cầu!");
		return false;
	}
	
	else if (holot.length > 40){
		alert("Họ lót có độ dài không quá 40 kí tự!");
		return false;
	}
	else if (ten.length > 10){
		alert("Tên có độ dài không quá 10 kí tự!");
		return false;
	}
	else if (sodt.length > 12){
		alert("Số điện thoại có độ dài không quá 12 kí tự!");
		return false;
	}
	
	else if (diachi.length > 100){
		alert("Địac chỉ có độ dài không quá 100 kí tự!");
		return false;
	}
	
	
	
	
	//---------------Phầm thêm vào để kiểm tra dữ liệu đầu vào (Nguyễn Ngọc Chánh )--------------------------
	else if(check_year()==false)
	{
		alert("Năm sinh không hợp lệ!");
		return false;
	}
	else if(isNaN(sodt))
	 {
		 alert("Số điện thoại phải là số!");
		
		 document.capnhatcanbo.txtsodt.focus();
		 document.capnhatcanbo.txtsodt.value="";
		 return false;
	 }
	else if(check_mail(email)==false){
		alert("Email không hợp lệ!");
		return false;
	}
	//----------------------------------------------------------------------------------------------------------------
	
	
	
	
	
	
	else if (email.length > 50){
		alert("Email có độ dài không quá 50 kí tự!");
		return false;
	}
	else if (loaicb=="DT" || loaicb=="AD"){
	 
	 	if (nghiepvu == ""){
			alert("Xin vui lòng nhập đầy đủ thông tin được yêu cầu!");
			return false;
		}
		else if (nghiepvu.length > 100){
			alert("Nghiệp vụ có độ dài không quá 100 kí tự!");
			return false;
		}
	 }
	 
	 else{
	 	if ( indexchucdanh == 0 || indexbomon == 0){
			alert("Xin vui lòng nhập đầy đủ thông tin được yêu cầu!");
			return false;
		}
		
	 
	 }
	 
		 
	 return true;
	 
}

function nhap(loaicb){
    
    if (loaicb=="DT" || loaicb=="AD"){
        document.capnhatcanbo.txtnghiepvu.disabled = false;
        //document.capnhatcanbo.cbokhoa.disabled = true;
        document.capnhatcanbo.cbobomon.disabled = true;
        document.capnhatcanbo.cbochucvu.disabled = true;
		document.capnhatcanbo.cbochucdanh.disabled = true;
    }
	else{
        document.capnhatcanbo.txtnghiepvu.disabled = true;
	 	//document.capnhatcanbo.cbokhoa.disabled = false;
        document.capnhatcanbo.cbobomon.disabled = false;
        document.capnhatcanbo.cbochucvu.disabled = false;
		document.capnhatcanbo.cbochucdanh.disabled = false;
	}
}


function empty(){
	//document.capnhatcanbo.cboloaicb.selectedIndex = 0;
	document.capnhatcanbo.txtmaso.value = "";
	document.capnhatcanbo.txtholot.value = "";
	document.capnhatcanbo.txtten.value = "";
	document.capnhatcanbo.txtngaysinh.value = "";
	document.capnhatcanbo.cbophai.selectedIndex = 0;
	document.capnhatcanbo.txtsodt.value = "";
	document.capnhatcanbo.txtdiachi.value = "";
	document.capnhatcanbo.txtemail.value = "";
	document.capnhatcanbo.cbohocvi.selectedIndex = 0;
	document.capnhatcanbo.txtnghiepvu.value = "";
	document.capnhatcanbo.cbobomon.selectedIndex = 0;
	document.capnhatcanbo.cbochucdanh.selectedIndex = 0;
	document.capnhatcanbo.cbochucvu.selectedIndex = 0;
	//document.capnhatcanbo.btnsua.disabled=true;
    //document.capnhatcanbo.btnxoa.disabled=true;
	
}
function confirmDelete(){
    if (confirm("Bạn có chắc muốn cán bộ này không?")){
        return true;
    }
    return false;
    
}
function confirmUpdate(){
    if (confirm("Bạn có chắc muốn sửa thông tin của cán bộ này không?")){
        return true;
    }
    return false;
    
}
$(function() {
	//$('#popupDatepicker').datepick();
	$('#inlineDatepicker').datepick({onSelect: showDate});
	$('#popupDatepicker').datepick();
	$('#popupDatepicker2').datepick();
});
 
function showDate(date) {
	alert('The date chosen is ' + date);
}
</script>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<link href="Libraries/css/jquery.datepick.css" rel="stylesheet" type="text/css">
<style type="text/css">
.table_left_text {
	text-align: right;
}
.table_center {
	text-align: center;
}
</style>
</head>
<title>Untitled Document</title>
</head>

<body>
<form name="capnhatcanbo" method="POST">
<table align="center" class="font" width="800" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td class=main_1><img border="0" src="Libraries/images/tbl_left.gif" width="10" height="25" /></td>
    <td align=center class=main_1>Cập Nhật Cán Bộ </td>
    <td class=main_1><p align="right"><img border="0" src="Libraries/images/tbl_right.gif" width="10" height="25" /></p></td>
  </tr>
  <tr bgcolor="#dae9f3">
    <td class="border_1" colspan="3" valign="top"><table width="737" height="252" border="0">
      <tr>
        <td>&nbsp;</td>
        <td colspan="2">&nbsp;</td>
        <td>&nbsp;</td>
      </tr>
      <tr>
        <td class="table_left_text">Loại CB</td>
        <td><select name="cboloaicb" id="cboloaicb" onChange="empty();nhap(this.value);taoMaCB();">
          <option value=""></option>
          <option value="AD"<?php if ($_POST['cboloaicb']=='AD') echo "selected='selected'"; ?>>Cán bộ quản trị</option>
          <option value="DT"<?php if ($_POST['cboloaicb']=='DT') echo "selected='selected'"; ?>>Cán bộ đào tạo</option>
          <option value="GV"<?php if ($_POST['cboloaicb']=='GV') echo "selected='selected'"; ?>>Cán bộ giảng dạy</option>
        </select></td>
        <td class="table_left_text">MSCB</td>
        <td><input name="txtmaso" type="text" id="txtmaso" size="30" onKeyUp="hienThiThongTinCB(document.capnhatcanbo.cboloaicb.value,this.value);"/>
          <?PHP 
				if (isset($_POST['txtmaso'])){
                    echo "<script language=\"javascript\">document.capnhatcanbo.txtmaso.value='$maso'</script>";
                }
			?></td>
      </tr>
      <tr>
        <td class="table_left_text">H&#7885; L&oacute;t</td>
        <td><input name="txtholot" type="text" id="txtholot" size="30"/>
          <?php 
				if (isset($_POST['txtholot'])){
                    echo "<script language=\"javascript\">document.capnhatcanbo.txtholot.value='$holot'</script>";
                }
			?></td>
        <td class="table_left_text">T&ecirc;n</td>
        <td><input name="txtten" type="text" id="txtten" size="30"/>
          <?php 
				if (isset($_POST['txtten'])){
                    echo "<script language=\"javascript\">document.capnhatcanbo.txtten.value='$ten'</script>";
                }
			?></td>
      </tr>
      <tr>
        <td class="table_left_text">Ng&agrave;y Sinh</td>
        <td><input name="txtngaysinh" type="text" id="popupDatepicker" size="30" maxlength="12" readonly="true" />
          <?php 
				if (isset($_POST['txtngaysinh'])){
                    echo "<script language=\"javascript\">document.capnhatcanbo.txtngaysinh.value='$ngaysinh'</script>";
                }
			?></td>
        <td class="table_left_text">Ph&aacute;i</td>
        <td><select name="cbophai">
          <option value=""></option>
          <option value="1"<?php if ($_POST['cbophai']=='1') echo "selected='selected'"; ?>>Nam</option>
          <option value="0"<?php if ($_POST['cbophai']=='0') echo "selected='selected'"; ?>>Nữ</option>
        </select></td>
      </tr>
      <tr>
        <td class="table_left_text">S&#7889; &#272;T </td>
        <td><input name="txtsodt" type="text" id="txtsodt" size="30"/>
          <?php 
				if (isset($_POST['txtsodt'])){
                    echo "<script language=\"javascript\">document.capnhatcanbo.txtsodt.value='$sodt'</script>";
                }
			?></td>
        <td class="table_left_text">Email</td>
        <td><input name="txtemail" type="text" id="txtemail" size="30"/>
          <?php 
				if (isset($_POST['txtemail'])){
                    echo "<script language=\"javascript\">document.capnhatcanbo.txtemail.value='$email'</script>";
                }
			?></td>
      </tr>
      <tr>
        <td class="table_left_text">Địa chỉ</td>
        <td colspan="3"><input name="txtdiachi" type="text" id="txtdiachi" size="30"/>
          <?php 
				if (isset($_POST['txtdiachi'])){
                    echo "<script language=\"javascript\">document.capnhatcanbo.txtdiachi.value='$diachi'</script>";
                }
			?></td>
        </tr>
      <tr>
        <td class="table_left_text">H&#7885;c V&#7883;</td>
        <td><select name="cbohocvi">
          <option value=""></option>
          <option value="CN"<?php if ($_POST['cbohocvi']=='CN') echo "selected='selected'"; ?>>Cử nhân</option>
          <option value="KS"<?php if ($_POST['cbohocvi']=='KS') echo "selected='selected'"; ?>>Kĩ sư</option>
          <option value="ThS"<?php if ($_POST['cbohocvi']=='ThS') echo "selected='selected'"; ?>>Thạc sĩ</option>
          <option value="TS"<?php if ($_POST['cbohocvi']=='TS') echo "selected='selected'"; ?>>Tiến sĩ</option>
          <option value="PGS"<?php if ($_POST['cbohocvi']=='PGS') echo "selected='selected'"; ?>>Phó giáo sư</option>
          <option value="GS"<?php if ($_POST['cbohocvi']=='GS') echo "selected='selected'"; ?>>Giáo sư</option>
        </select></td>
        <td class="table_left_text">Nghiệp vụ</td>
        <td><input name="txtnghiepvu" type="text" id="txtnghiepvu" size="30" disabled="true"/>
          <?php 
				if (isset($_POST['txtnghiepvu'])){
                    echo "<script language=\"javascript\">document.capnhatcanbo.txtnghiepvu.value='$nghiepvu'</script>";
                }
			?></td>
      </tr>
      <tr>
        <td class="table_left_text">Ch&#7913;c Danh</td>
        <td><select name="cbochucdanh">
          <option value=""></option>
          <option value="GVC"<?php if ($_POST['cbochucdanh']=='GVC') echo "selected='selected'"; ?>>Giảng viên chính</option>
          <option value="GV"<?php if ($_POST['cbochucdanh']=='GV') echo "selected='selected'"; ?>>Giảng viên</option>
          <option value="TG"<?php if ($_POST['cbochucdanh']=='TG') echo "selected='selected'"; ?>>Trợ giảng</option>
        </select></td>
        <td class="table_left_text">Ch&#7913;c V&#7909;</td>
        <td><select name="cbochucvu">
          <option value=""></option>
          <option value="DV"<?php if ($_POST['cbochucvu']=='DV') echo "selected='selected'"; ?>>Lãnh đạo đơn vị</option>
          <option value="BM"<?php if ($_POST['cbochucvu']=='BM') echo "selected='selected'"; ?>>Lãnh đạo bộ môn</option>
          <?php
					/*$db = new database();
                    $db->setQuery("select * from ChucVu");
                    $result = $db->fetchAll();
                    while($rows = mysql_fetch_array($result)){
                        echo "<option value='".$rows['macv']."'>".$rows['tencv']."</option>";
                    }*/
				?>
        </select></td>
      </tr>
      <tr>
        <td class="table_left_text">B&#7897; M&ocirc;n </td>
        <td><select name="cbobomon">
          <option value=""></option>
          <?php
						
					$bm = new BoMon();
					
					$result = $bm->dsTatCaBM();
					while ($rows = mysql_fetch_array($result)){
						echo "<option value='".$rows['mabm']."'>".$rows['tenbm']."</option>";
					}
					 if (isset($_POST['cbobomon'])) {
						
						echo "<script language=\"javascript\">";
						
						echo "for (var i = 0; i< document.capnhatcanbo.cbobomon.length; i++){";
						echo "if (document.capnhatcanbo.cbobomon[i].value == '$mabm'){";
						echo "document.capnhatcanbo.cbobomon.selectedIndex = i;";
						echo "break;";
						echo "}";
						echo "}";
						
						echo "</script>";
					}		
						
				?>
        </select></td>
        <td class="table_left_text">&nbsp;</td>
        <td>&nbsp;</td>
      </tr>
      <tr>
        <td colspan="4" class="table_center"><input type="button" name="btntaomoi" value="Tạo mới" class="button_1" onClick="empty();taoMaCB();"/>
          &nbsp;
          <input type="submit" name="btnthem" value="Thêm" class="button_1" onClick="return checkField(); "  />
          &nbsp;
          <input type="submit" name="btnsua" value="Sửa" class="button_1" onClick=" return checkField();"/>
          &nbsp;
          <input type="submit" name="btnxoa" value="Xóa" class="button_1" onClick="confirmDelete();"/></td>
      </tr>
    </table></td>
  </tr>
</table>
<p>&nbsp;</p>
<p><br/>
  <br/>
</p>
<div id="danhsachcn">
  <?php
//if ($_SERVER['REQUEST_METHOD'] == 'POST') 
//{
    
    //if (isset($_POST['btnxem'])){
	/*$quyen = new Quyen();
    $quyen->setMaQuyen('AD');
	$result = $quyen->dsChucNangQuenThucHien();
        echo "<table align='center' class='font' width='800' border='0' cellspacing='0' cellpadding='0'>";
          echo "<tr>";
            echo "<td class='main_1'><img border='0' src='Libraries/images/tbl_left.gif' width='10' height='25' /></td>";
            echo "<td align='center' class='main_1'>Danh sách Khoa</td>";
            echo "<td class='main_1'><p align='right'><img border='0' src='Libraries/images/tbl_right.gif' width='10' height='25' /></p></td>";
          echo "</tr>";
          echo "<tr >";
            echo "<td class='border_1' colspan='3' valign='top'><table width='800' class='border_1' style='border:none' id='tbmain' cellpadding='0' cellspacing='0'>";
              echo "<tr>";
                echo "<td width='30' align='center' class='main_3'>STT</td>";
                echo "<td width='50' align='center' class='main_3'>Mã CN</td>";
                echo "<td width='300' align='center' class='main_3'>Tên Chức năng </td>";
                echo "<td width='200' align='center' class='main_3'>Hình Ảnh </td>";
                echo "<td width='100' align='center' class='main_3'>Parent</td>";
        		echo "<td width='50' align='center' class='main_3'>Chọn</td>";
                
                echo "</tr>";
             
          
        	
        	 	
        		
        		
        		$bg=($curPg-1)*10+1;
        		$end=$bg+9;	
        		$num=mysql_num_rows($result);
        		$i=0;
        		$ci=0;
        		
        		while($row=mysql_fetch_array($result))
        		{
  		            
        			$i++;
        			$ci=2-$i%2;
        			
        			echo "<tr>";
        			echo "<td align='center' class='main_3'>".$i."</td>";
                    echo "<td class='level_1_$ci' align='center'><div id='macn$i'>".$row['macn']."</div></td>";
        			echo "<td class='level_1_$ci' align='left'><div id='tencn$i'>".$row['tencn']."</div></td>";
        			echo "<td class='level_1_$ci' align='center'><div id='hinhanh$i'>".$row['hinhanh']."</div></td>";
                    echo "<td class='level_1_$ci' align='center'><div id='parent$i'>".$row['parent']."</div></td>";
        			
        		
        			echo "<td class='level_1_$ci' align='center'><input type='radio' name='chkchon' value='$i' onClick='getValue(this.value);' ></td>";
        		
        			echo "</tr>";
        		
        			
        		}
        		
        	
        
        
              
            echo "</table></td>";
          echo "</tr>";
        echo "</table>";*/
    //}
//}
?>
</div>
</form>
</body>
</html>
